---
title: "R7.Ideology_National"
---

# Load Packages
```{r}
library(tidyverse)
```

# Load Data
```{r}
load("Data/nation_ideo.Rdata")
```

# Plot Vote Share Trends/Ideological Grouping Nationally over Time
```{r}

national_panel <- do.call(rbind, nation_ideo) %>% group_by(year, ideology2) %>% 
  summarise(votes = sum(votes)) %>% mutate(vs = votes/sum(votes)) %>% 
  filter(!is.na(ideology2)) %>% 
  mutate(ideology2 = ifelse(ideology2 == "Center", "Center-Left", ideology2), 
         ideology2 = ifelse(ideology2 == "Left", "Far Left", ideology2))
  
national_panel$ideology2 <- factor(national_panel$ideology2, level = c("Communist", "Far Left", "Center-Left", "Right"))

national_panel %>% 
  filter(year <= 1987) %>% 
  ggplot(aes(x = as.factor(year), col = as.factor(ideology2), shape = ideology2, group = ideology2)) +
        geom_point(aes(y = vs)) +
        geom_line(aes(y = vs)) +
        # facet_wrap(~ exp_cat2) +
        # ggtitle("Vote Share Trends by Ideological Group") +
        theme_light() + 
        xlab("Election Year") + ylab("Vote Share") +
        scale_color_grey(name = "Ideology") +
        scale_shape_discrete(name = "Ideology") +
        theme(axis.text.x = element_text(angle = 90)) 
    
ggsave(plot = last_plot(),
      "Figures/Afg1d3_VSNational.pdf",
       width = 7, height = 5)

```
